package com.copm.ifm.servers.sys.dataauth;

import com.copm.ifm.base.service.mp.dataauth.component.DataAuthCacheHelper;
import com.copm.ifm.servers.sys.entity.SysStaff;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * 添加数据权限限制配置
 *
 * @author zzf
 * @date 2020/12/21 11:45
 */
@Component
public class DataAuthCacheInit implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        DataAuthCacheHelper helper = new DataAuthCacheHelper()
                .setSqlHandler(new MyRoleDataAuthSqlHandler())
                .addTargetEntityClass(SysStaff.class)
                .setTargetFieldName(SysStaff::getTenantId)
                .bind();
        helper.cache();
    }
}
